<template>
    <el-dialog v-model="dialogFormVisible" :title="title" @close="closeDialog">
        <el-form :model="addBaseAchievementClassMetricsForm" ref="addBaseAchievementClassMetricsRef" :rules="addBaseAchievementClassMetricsrules">
                        <el-form-item label="唯一标识符" :label-width="formLabelWidth"
                                      prop="id" v-if="addBaseAchievementClassMetricsForm.id">
                            <el-input
                                    v-model="addBaseAchievementClassMetricsForm.id"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写唯一标识符"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="班级标识符" :label-width="formLabelWidth"
                                      prop="classId" v-if="addBaseAchievementClassMetricsForm.id">
                            <el-input
                                    v-model="addBaseAchievementClassMetricsForm.classId"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写班级标识符"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="年级标识符" :label-width="formLabelWidth"
                                      prop="gradeId" v-if="addBaseAchievementClassMetricsForm.id">
                            <el-input
                                    v-model="addBaseAchievementClassMetricsForm.gradeId"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写年级标识符"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="校区编号" :label-width="formLabelWidth"
                                      prop="campus" v-if="addBaseAchievementClassMetricsForm.id">
                            <el-input
                                    v-model="addBaseAchievementClassMetricsForm.campus"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写校区编号"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="984指标" :label-width="formLabelWidth"
                                      prop="index984" v-if="addBaseAchievementClassMetricsForm.id">
                            <el-input
                                    v-model="addBaseAchievementClassMetricsForm.index984"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写984指标"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="211指标" :label-width="formLabelWidth"
                                      prop="index211" v-if="addBaseAchievementClassMetricsForm.id">
                            <el-input
                                    v-model="addBaseAchievementClassMetricsForm.index211"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写211指标"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="重本指标" :label-width="formLabelWidth"
                                      prop="indexKey" v-if="addBaseAchievementClassMetricsForm.id">
                            <el-input
                                    v-model="addBaseAchievementClassMetricsForm.indexKey"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写重本指标"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="一本指标" :label-width="formLabelWidth"
                                      prop="indexGaokao" v-if="addBaseAchievementClassMetricsForm.id">
                            <el-input
                                    v-model="addBaseAchievementClassMetricsForm.indexGaokao"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写一本指标"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="综合贡献率计算方法" :label-width="formLabelWidth"
                                      prop="calculationMethod">
                            <el-input
                                    v-model="addBaseAchievementClassMetricsForm.calculationMethod"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写综合贡献率计算方法"
                            ></el-input>
                        </el-form-item>
                        <el-form-item label="考试标识符" :label-width="formLabelWidth"
                                      prop="examId" v-if="addBaseAchievementClassMetricsForm.id">
                            <el-input
                                    v-model="addBaseAchievementClassMetricsForm.examId"
                                    autocomplete="off"
                                    ref="name"
                                    placeholder="请填写考试标识符"
                            ></el-input>
                        </el-form-item>
        </el-form>
        <template #footer>
      <span class="dialog-footer">
        <el-button @click="cancel()">取消</el-button>
        <el-button type="primary" @click="save()">保存</el-button>
      </span>
        </template>
    </el-dialog>
</template>

<script>
    import {ref} from "vue";
    import {httpService} from "@/utils/httpService";
    import {ElMessage, ElForm} from "element-plus";
    import {vxRule} from "@/utils/validator";

    export default {
        name: "AddBaseAchievementClassMetrics",
        components: {ElForm, ElMessage},
        data() {
            return {
                dialogFormVisible: ref(false),
                formLabelWidth: "120px",
                title: "",
                personnelType: "",
                addBaseAchievementClassMetricsForm: {
                    id: "",
                    classId: "",
                    gradeId: "",
                    campus: "",
                    index984: "",
                    index211: "",
                    indexKey: "",
                    indexGaokao: "",
                    calculationMethod: "",
                    examId: "",
                },
                // 校验规则
                addBaseAchievementClassMetricsrules: {
                    calculationMethod: vxRule(true, null, "blur"),
                },
            };
        },
        methods: {
            closeDialog() {
                this.clear();
            },
            cancel() {
                this.dialogFormVisible = false;
                this.clear();
            },
            getBaseAchievementClassMetricsById(id) {
                httpService("/javaApi/baseAchievementClassMetrics/queryById", {id: id}, "get").then(
                    (data) => {
                        this.addBaseAchievementClassMetricsForm = data;
                    }
                );
            },
            clear() {
                this.dialogFormVisible = false;
                //清空form
                    this.addBaseAchievementClassMetricsForm.id = "";
                    this.addBaseAchievementClassMetricsForm.classId = "";
                    this.addBaseAchievementClassMetricsForm.gradeId = "";
                    this.addBaseAchievementClassMetricsForm.campus = "";
                    this.addBaseAchievementClassMetricsForm.index984 = "";
                    this.addBaseAchievementClassMetricsForm.index211 = "";
                    this.addBaseAchievementClassMetricsForm.indexKey = "";
                    this.addBaseAchievementClassMetricsForm.indexGaokao = "";
                    this.addBaseAchievementClassMetricsForm.calculationMethod = "";
                    this.addBaseAchievementClassMetricsForm.examId = "";
            },
            save() {
                this.$refs.addBaseAchievementClassMetricsRef.validate((valid) => {
                    if (valid) {
                        let params = new FormData(); //创建一个form对象,必须是form对象否则后端接受不到数据
                        params.append("id", this.addBaseAchievementClassMetricsForm.id);
                        params.append("classId", this.addBaseAchievementClassMetricsForm.classId);
                        params.append("gradeId", this.addBaseAchievementClassMetricsForm.gradeId);
                        params.append("campus", this.addBaseAchievementClassMetricsForm.campus);
                        params.append("index984", this.addBaseAchievementClassMetricsForm.index984);
                        params.append("index211", this.addBaseAchievementClassMetricsForm.index211);
                        params.append("indexKey", this.addBaseAchievementClassMetricsForm.indexKey);
                        params.append("indexGaokao", this.addBaseAchievementClassMetricsForm.indexGaokao);
                        params.append("calculationMethod", this.addBaseAchievementClassMetricsForm.calculationMethod);
                        params.append("examId", this.addBaseAchievementClassMetricsForm.examId);
                        if (this.addBaseAchievementClassMetricsForm.id) {
                            params.append("id", this.addBaseAchievementClassMetricsForm.id);
                            httpService("/javaApi/baseAchievementClassMetrics/edit", params, "post").then(
                                (data) => {
                                    if (data.code == 200) {
                                        ElMessage.success("修改成功");
                                        this.clear();
                                        //刷新父组件的数据
                                        this.$parent.getBaseAchievementClassMetricsList();
                                    } else {
                                        ElMessage.error("修改失败");
                                    }
                                }
                            );
                        } else {
                            httpService("/javaApi/baseAchievementClassMetrics/add", params, "post").then(
                                (data) => {
                                    if (data.code == 200) {
                                        ElMessage.success("添加成功");
                                        this.clear();
                                        //刷新父组件的数据
                                        this.$parent.getBaseAchievementClassMetricsList();
                                    } else {
                                        ElMessage.error("添加失败");
                                    }
                                }
                            );
                        }
                    } else {
                        return false;
                    }
                });
            },
        },
    };
</script>
<style>
</style>